// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: linchuan

#pragma once

#include <cstdio>
#include <map>
#include <memory>
#include <string>
#include <vector>

#include <rapidjson/document.h>

#include "coin2/exchange/base/order/order.h"
#include "coin2/exchange/korbit/symbology/currency.h"
#include "coin2/exchange/korbit/symbology/product.h"

namespace coin2::exchange::korbit::order_v1 {

class KorbitParser : public base::order::BaseParser {
 public:
  const ParseResult& ParseRawMessage(const RawMessage& msg) override;
  AccountBalance ParseBalance(const JsonValue& doc) override;

 private:
  void ParseAccountToken();
  void ParseSubmitResponse();
  void ParseCancelResponse();
  void ParseRestOpenOrdersInfo();
  void ParseRestDoneOrdersInfo();
  void ParseRestFillInfoList();
  void ParseRestAccountBalance();
  void ParseWsMessage();

  std::string ParseAuthToken(const JsonValue& doc);
  ProductOrderBundle ParseRestDoneOrderInfoList(const JsonValue& data);
  ProductOrderBundle ParseRestOpenOrderInfoList(const JsonValue& data);
};

}  // namespace coin2::exchange::korbit::order_v1
